package com.oe.market.modules.ele.service;

import com.oe.market.modules.base.ex.BusinessException;
import com.oe.market.modules.ele.model.bean.Cookie;
import com.oe.market.modules.ele.model.bean.RedPackage;
import com.oe.market.modules.ele.model.dao.CookieDao;
import com.oe.market.modules.ele.model.dao.CookieUseCountDao;
import com.oe.market.modules.ele.model.dao.RedPackageDao;

import java.util.List;
import java.util.concurrent.TimeUnit;

public class EleAutoService {

    // @note 零点 自动使用机器人，检索没有检索过的红包，例如 robot list 为空的红包
    public static void checkRedPackage() {
        List<Cookie> cookies = CookieDao.me.searchUse();
        List<RedPackage> redPackages = RedPackageDao.me.searchUseful();
        Integer cookiePos = cookies.size() - 1;
        int i = 0;
        for (RedPackage redPackage : redPackages) {
            System.out.println(i++);
            try {
                EleRedPackageService.checkRedPackageCurrentPos(redPackage, cookies.get(cookiePos));
                TimeUnit.SECONDS.sleep(1);
            } catch (BusinessException e) {
                RedPackageDao.me.updateStatus(redPackage.groupSn, "invalid");
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            --cookiePos;
            if (cookiePos < 0)
                cookiePos = cookies.size() - 1;
        }
    }

    // @note today use 置为 0


    // 接码平台



    public static void main(String[] args) {
        EleAutoService.checkRedPackage();
    }
}
